export function request(options) {
	const baseURL = 'https://groupbuy.huishuokj.com'

	return new Promise((resolve, reject) => {
		options.url = `${baseURL}${options?.url}`;
		// 自动添加token
		if (!options?.headers || Object.keys(options?.headers).indexOf('xx-token') === -1) {
			options.header = {
				'xx-token': uni.getStorageSync('token'),
			}
		}
		options.success = (res) => {
			if (res.data.code === 10001) {
				uni.showToast({
					title: '登陆失效，请重新登陆!',
					icon: 'none'
				}).then(() => {
					uni.navigateTo({
						url: "/pages/user/second/login"
					});
				})
				return reject(res.data)
			}
			return resolve(res.data)
		}
		options.error = (error) => {
			return reject(error)
		}
		uni.request(options)
	});
}